﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.TeamFoundation.Client;
using TestPlanWordWriter.Common;
using Microsoft.TeamFoundation.TestManagement.Client;

namespace TestPlanWordWriter.UI
{
    public partial class CreateControlForm : Form
    {
        public TfsTeamProjectCollection TeamProjectCollection { get; set; }
        public string TeamProjectName { get; set; }
        public int? TestPlan { get; set; }
        public string TestPlanName { get; set; }

        public CreateControlForm()
        {
            InitializeComponent();

            lstTestPlan.DisplayMember = "Name";
            lstTestPlan.ValueMember = "Id";
        }

        private void CreateControlForm_Load(object sender, EventArgs e)
        {
            ITestPlanCollection testPlans = TfsGateway.GetTestPlans(this.TeamProjectCollection, this.TeamProjectName);

            lstTestPlan.Items.Clear();

            foreach (ITestPlan testPlan in testPlans)
            {
                TestPlanListInfo testPlanItem = new TestPlanListInfo()
                {
                    Id = testPlan.Id,
                    Name = testPlan.Name
                };
                
                lstTestPlan.Items.Add(testPlanItem);
            }
        }

        private void lstTestPlan_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstTestPlan.SelectedItem != null)
            {
                TestPlanListInfo currentItem = (TestPlanListInfo)lstTestPlan.SelectedItem;
                this.TestPlan = currentItem.Id;
                this.TestPlanName = currentItem.Name;
                btnOK.Enabled = true;
            }
            else
            {
                btnOK.Enabled = false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}
